<template>
    <div class="writeOrder">
        <IHeader class="header" back="true" title="生成订单"></IHeader>
        <scroller class="wrap conwrap">
            <div class="contact" v-if="addressList" @click="pushToMyAddress">
                <div class="contact-info">
                    <text class="name">{{addressList.consignee}}</text>
                    <text class="tel">{{addressList.phone}}</text>
                </div>
                <div class="addr">
                    <text class="address">{{addressList.provinceName}}{{addressList.cityName}}{{addressList.districtName}}{{addressList.address}}</text>
                    <image :src="imgPath('arrow_right.png')" class="arrow"></image>
                </div>
            </div>
            <div class="contact" v-if="!addressList" @click="pushToMyAddress">
                <div class="addr">
                    <text class="address">请先去添加收货地址</text>
                    <image :src="imgPath('arrow_right.png')" class="arrow"></image>
                </div>
            </div>
            <div>
                <image :src="imgPath('pic2.png')" class="xianImg"></image>
            </div>
            <div class="xian"></div>
            <div class="row">
                <text class="paytext">支付方式</text>
                <div class="pay">
                    <text class="text1">线下支付</text>
                </div>
            </div>
            <div class="xian"></div>
            <div class="row" @click="chooseFaPiaoType">
                <text class="paytext">是否需要发票</text>
                <div class="pay" >
                    <text class="text1">{{chooseEnterpriseType}}</text>
                    <image :src="imgPath('arrow_right.png')" class="arrow"></image>
                </div>
            </div>
            <div class="xian"></div>
            <div class="Item" v-for="(item, index) in carList" :key="index" v-if="carList.length > 0">
                <div class="store">
                    <div class="store-item">
                        <div class="store-info">
                            <image :src="imgPath('home.png')" class="storeImg"></image>
                            <text class="storename">{{item.shopName}}</text>
                        </div>
                        <div class="good-wrap">
                            <div class="good-item" v-if="item.goods.length === 1 && item.goods">
                                <image :src="item.goods[0].goodsUrl" class="goodImg"></image>
                                <div class="good-right">
                                    <text class="goodname">{{item.goods[0].goodsName}}</text>
                                    <div class="detail-info">
                                        <div class="hebing">
                                            <div class="type">
                                                <text class="text">订购类型：</text>
                                                <text class="text" v-if="item.goods[0].buyType === '1'">现货</text>
                                                <text class="text" v-if="item.goods[0].buyType === '2'">定制</text>
                                            </div>
                                            <div class="type">
                                                <text class="text">商品类型：</text>
                                                <text class="text" v-if="item.goods[0].goodsType === '1'">样品</text>
                                                <text class="text" v-if="item.goods[0].goodsType === '2'">大货</text>
                                            </div>
                                        </div>
                                        <text class="text">X{{item.goods[0].amount}}</text>
                                    </div>
                                    <div class="price">
                                        <!--<div class="nowPrice">-->
                                            <!--<text class="money">￥</text>-->
                                            <!--<text class="money">{{item.goods[0].discountPrice}}</text>-->
                                        <!--</div>-->
                                        <!--<div class="nowPrice" v-if="item.goods[0].price">-->
                                            <!--<text class="oldmoney">原价 ￥</text>-->
                                            <!--<text class="oldmoney">{{item.goods[0].price}}</text>-->
                                        <!--</div>-->
                                        <div class="nowPrice" v-if="item.goods[0].discountPrice">
                                            <text class="money">{{'￥' + item.goods[0].discountPrice}}{{'/' + item.goods[0].priceUnit}}</text>
                                        </div>
                                        <div class="nowPrice">
                                            <text class="oldmoney">{{item.goods[0].discountPrice ? '原价 ￥' + item.goods[0].price : item.goods[0].price}}{{'/' + item.goods[0].priceUnit}}</text>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="good-wrap" v-if="item.goods && item.goods.length === 2">
                                <div class="good-item goods-items">
                                    <div class="good-left">
                                        <image :src="goodItem.goodsUrl" class="goodImg" v-for="goodItem in item.goods" :key="goodItem.id"></image>
                                    </div>
                                    <div class="good-rightimg" @click="lookMore(item)">
                                        <image :src="imgPath('write.png')" class="more"></image>
                                    </div>
                                </div>
                            </div>
                            <div class="good-wrap" v-if="item.goods && item.goods.length > 2">
                                <div class="good-item goods-items">
                                    <div class="good-left">
                                        <image :src="item.goods[0].goodsUrl" class="goodImg"></image>
                                        <image :src="item.goods[1].goodsUrl" class="goodImg"></image>
                                        <image :src="item.goods[2].goodsUrl" class="goodImg"></image>
                                    </div>
                                    <div class="good-rightimg" @click="lookMore(item)">
                                        <image :src="imgPath('write.png')" class="more"></image>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="row2">
                        <text class="paytext">运费</text>
                        <div class="pay">
                            <text class="text1">到付</text>
                        </div>
                    </div>
                    </div>
                    <div class="row" @click="showFahuoType">
                        <div class="row2">
                            <text class="paytext">发货方式</text>
                            <div class="pay">
                                <text class="text1">{{chooseFaHuoType}}</text>
                                <image :src="imgPath('arrow_right.png')" class="arrow"></image>
                            </div>
                        </div>
                    </div>
                    <div class="beizhu">
                        <text class="beizhutext">订单备注：</text>
                        <textarea  cols="30" rows="10" class="beizhuCon" maxlength="300" v-model="oneText" placeholder="对于本次交易说明，可以与商家达成协议(300字以内)"></textarea>
                    </div>
                    <div class="xian"></div>
                </div>
            </div>
            <div class="priceRow ">
                <div class="row2">
                <text class="jine">金额</text>
                <div class="mon">
                    <text class="moneytext">￥{{allMoney}}</text>
                </div>
            </div>
            </div>
            <div class="priceRow">
                <image :src="imgPath(disAgree? 'noxuanzhong.png':'xuanzhong.png')" class="icon" @click="changeXuanZhong"></image>
                <text class="agree">我已同意《泳衣库服务协议》</text>
            </div>
            <div class="footer">
                <div class="left">
                    <text class="yingfu">应付</text>
                    <div class="mon">
                        <text class="moneytext">￥{{allMoney}}</text>
                    </div>
                </div>
                <div class="right" @click="pushToCheckstand">
                    <text class="apply">提交订单</text>
                </div>
            </div>
        </scroller>
        <!--选择发票类型-->
        <wxc-popup popup-color="#fff" :show="typeSelectShow" ref="wxcPopup" @wxcPopupOverlayClicked="closeFaPiaoDialog"   pos="right">
            <div class="dialog-content">
                <IHeader class="header" back="true" close="true" title="选择发票" @closeDialog="closeFaPiaoDialog"></IHeader>
                <list class="enterprise-list">
                    <cell class="enterprise-item" @click="chooseThisEnterprise(item,index)" v-for="(item, index) in fapiaoTypeList" :class="[idx ==index ?  'afterpress': 'beforepress']" @touchend="typeTouchEnd()"  @touchstart="typeTouchStart(item, index)"   :key="index">
                        <text  class="enterprise-name item-height col_464646">{{item.name}}</text>
                    </cell>
                </list>
            </div>
        </wxc-popup>
        <!--选择发货类型-->
        <wxc-popup popup-color="#fff" :show="typeFahuoShow" ref="wxcPopup" @wxcPopupOverlayClicked="closeTypeDialog"  pos="right">
            <div class="dialog-content">
                <IHeader class="header" back="true" close="true" title="选择发货方式" @closeDialog="closeTypeDialog"></IHeader>
                <list class="enterprise-list">
                    <cell class="enterprise-item" @click="chooseThisFaHuo(item,index)" v-for="(item, index) in fahuoTypeList" :class="[idx1 ==index ?  'afterpress': 'beforepress']" @touchend="typeTouchEnd()"  @touchstart="typeTouchStart(item, index)"   :key="index">
                        <text  class="enterprise-name item-height col_464646">{{item.description}}</text>
                    </cell>
                </list>
            </div>
        </wxc-popup>
        <!--收货地址列表-->
        <wxc-popup popup-color="#fff" :show="shouHuoAddress" ref="wxcPopup" @wxcPopupOverlayClicked="closeshouHuoAddress"   pos="right">
            <div class="dialog-content">
                <div class="my-address">
                    <div class="header">
                        <div class="backPage" @click="backPage">
                            <image class="arrow_left" :src="imgPath('back.png')"></image>
                            <text class="back col_fff medium">返回</text>
                        </div>
                        <text class="title col_fff regular">收货地址</text>
                        <div class="btn-wrapper">
                            <text class="btn" @click="add">添加地址</text>
                        </div>
                    </div>
                    <scroller class="wrap">
                        <!--地址为空的时候-->
                        <div class="wrap wrap1" v-if=" !shouHuoAddressList.length > 0" >
                            <image :src="imgPath('null_add.png')" class="nullAddress"></image>
                            <text class="nulltext">一个地址也没有，快去添加地址吧!</text>
                        </div>
                        <div class="address-wrap" v-for="(item, index) in shouHuoAddressList" :key="index" v-if="shouHuoAddressList.length > 0">
                            <div class="contact-item" v-if="item.openDefaultAddress === '1'">
                                <div class="contact">
                                    <div class="contact-info">
                                        <text class="name">{{item.consignee}}</text>
                                        <text class="tel">{{item.phone}}</text>
                                        <text class="moren">默认</text>
                                    </div>
                                    <div class="addr">
                                        <text class="address">{{item.provinceName}}{{item.cityName}}{{item.districtName}}{{item.address}}</text>
                                        <image :src="imgPath('bianji.png')" class="addImg" @click="pushToWriteAdd(item, item.id)"></image>
                                    </div>
                                </div>
                                <div>
                                    <image :src="imgPath('colorxian.png')" class="xianImg"></image>
                                </div>
                            </div>
                            <div class="contact-item" v-if="item.openDefaultAddress === '0'">
                                <div class="contact" @click="pushToWriteOrder(item.id)">
                                    <div class="contact-info"><text class="name">{{item.consignee}}</text>
                                        <text class="tel">{{item.phone}}</text>
                                    </div>
                                    <div class="addr">
                                        <text class="address">{{item.provinceName}}{{item.cityName}}{{item.districtName}}{{item.address}}</text>
                                        <image :src="imgPath('bianji.png')" class="addImg" @click="pushToWriteAdd(item, item.id)"></image>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </scroller>
                </div>
            </div>
        </wxc-popup>
        <!--编辑收货地址-->
        <wxc-popup popup-color="#fff" :show="editAddress" ref="wxcPopup" @wxcPopupOverlayClicked="closeeditAddress"  pos="right">
            <div class="dialog-content">
                <div class="writeAdderss">
                    <div class="header">
                        <div class="backPage" @click="closeeditAddress">
                            <image class="arrow_left" :src="imgPath('back.png')"></image>
                            <text class="back col_fff medium">返回</text>
                        </div>
                        <text class="title col_fff regular">编辑地址</text>
                        <div class="btn-wrapper"  v-if="addressList">
                            <text class="btn" @click="saveAddress">保存</text>
                        </div>
                        <div class="btn-wrapper"  v-if="!addressList">
                            <text class="btn" @click="addNewAddress">保存</text>
                        </div>
                    </div>
                    <div class="wrap">
                        <div class="inputRows">
                            <div class="input">
                                <div class="leftInput">
                                    <text class="rowtext">收货人</text>
                                    <input type="text" class="rowInput" placeholder="请输入收货人姓名" v-model="addressData.consignee">
                                </div>
                                <image :src="imgPath('lianxiren.png')" class="rowImg"></image>
                            </div>
                        </div>
                        <div class="inputRows">
                            <div class="input">
                                <div class="leftInput">
                                    <text class="rowtext">联系方式</text>
                                    <input type="text" class="rowInput" placeholder="请输入联系方式" v-model="addressData.phone">
                                </div>
                                <image :src="imgPath('lianxidianhua.png')" class="rowImg"></image>
                            </div>
                        </div>
                        <div class="inputRows" v-if="showNo">
                            <div class="input"  @click="handleSelectArea">
                                <div class="leftInput">
                                    <text class="rowtext">所在地区</text>
                                    <text v-if="addressData.write">{{province}}</text>
                                </div>
                                <div class="leftInput" >
                                    <text class="choose" >请选择</text>
                                    <image :src="imgPath('arrow_right.png')" class="arrowImg"></image>
                                </div>
                            </div>
                        </div>
                        <div class="inputRows" v-if="showYes">
                            <div class="input"  @click="handleSelectArea">
                                <div class="leftInput">
                                    <text class="rowtext">所在地区</text>
                                    <text class="addstr">{{str}}</text>
                                </div>
                                <image :src="imgPath('arrow_right.png')" class="arrowImg"></image>
                            </div>
                        </div>
                        <div class="inputRows">
                            <div class="input">
                                <div class="leftInput">
                                    <text class="rowtext">详细地址</text>
                                    <input type="text" class="addInput rowInput" placeholder="请输入详细的的地址信息" v-model="addressData.address">
                                </div>
                            </div>
                        </div>
                        <div class="setting">
                            <Check :show="true" @doclick="chooseMoren" :checked="checkedIcon"></Check>
                            <text class="morentext">设置默认地址</text>
                        </div>
                        <div class="delete">
                            <text class="delete-btn" @click="deleteAddress" v-if="addressData.baocun1">删除地址</text>
                        </div>
                    </div>
                    <Address :show="addressShow" @cancel="handleAddressCancel" @confirm="handleAddressConfirm"></Address>
                </div>
            </div>
        </wxc-popup>
        <div  class="moremodal" v-if="moreGoodShow" @click="stopEvent">
            <div class="dialog-content1">
                <div class="store-item">
                    <div class="moreHeader">
                        <div class="headerText">
                            <text class="titletext1">购物车商品详情</text>
                            <text class="titletext2">共计{{moreGoodList.length}}件</text>
                        </div>
                        <image :src="imgPath('dialog_close.png')" class="closeImg" @click="closemoreGoodShow"></image>
                    </div>
                    <div class="good-wrap">
                        <div class="good-item" v-for="(item, index) in moreGoodList" :key="index">
                            <image :src="item.goodsUrl" class="goodImg"></image>
                            <div class="good-right">
                                <text class="goodname">{{item.goodsName}}</text>
                                <div class="detail-info">
                                    <div class="hebing">
                                        <div class="type">
                                            <text class="text">订购类型：</text>
                                            <text class="text" v-if="item.buyType === '1'">现货</text>
                                            <text class="text" v-if="item.buyType === '2'">定制</text>
                                        </div>
                                        <div class="type">
                                            <text class="text">商品类型：</text>
                                            <text class="text" v-if="item.goodsType === '1'">样品</text>
                                            <text class="text" v-if="item.goodsType === '2'">大货</text>
                                        </div>
                                    </div>
                                    <text class="text">X{{item.amount}}</text>
                                </div>
                                <div class="price">
                                    <div class="nowPrice" v-if="item.discountPrice">
                                        <text class="money">￥</text>
                                        <text class="money">{{item.discountPrice}}</text>
                                    </div>
                                    <div class="nowPrice">
                                        <text class="oldmoney">原价 ￥</text>
                                        <text class="oldmoney">{{item.price}}</text>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import IHeader from '@/components/header'
import { WxcPopup } from 'weex-ui'
import { queryInvoice } from '@/api/user'
import {faHuoMethod, productOrder, morenAddress, getAddress, updateAddress, deleteAddress, addAddress, searchAddress} from '@/api/order'
import Address from '@/components/address'
import Radio from '@/components/radio'
import Check from '@/components/check'
import { validatenull } from '@/util/validate'
const modal = weex.requireModule('modal')
const storage = weex.requireModule('storage')

export default {
  name: 'writeOrder',
  data () {
    return {
      userId: null, // 用户ID
      invoiceId: '', // 用户发票ID
      typeSelectShow: false,
      idx: -1,
      idx1: 0,
      chooseEnterpriseType: '否',
      chooseFaHuoType: '请选择',
      typeFahuoShow: false,
      fahuoTypeList: [],
      oneText: '',
      manyText: '',
      goosName: '',
      params: [],
      displayNone: false,
      invoice: [],
      fapiaoTypeList: [{'name': '是'}, {'name': '否'}],
      addressList: {},
      provinceList: [],
      shouHuoAddressList: [],
      shouHuoAddress: false,
      addressShow: false, // 地址选择显示
      showNo: true,
      showYes: false,
      str: '', // 地区数据
      addressData: {},
      editAddress: false,
      stringList: [],
      idList: [],
      cityId: '',
      dult: '0',
      checkedIcon: false,
      shoucang: false,
      allMoney: 0, // 总钱
      carList: [], // 购物车传来的数据
      moreGoodShow: false, // 填写订单多种商品显示
      moreGoodList: [], // 更多商品列表
      disAgree: false // 不同意协议
    }
  },
  computed: {
    // total () {
    //   return this.params.price * this.params.number
    // },
    // actual () {
    //   return this.params.discountPrice * this.params.number
    // },
    province () {
      return this.addressData.provinceName + this.addressData.cityName + this.addressData.districtName
    }
  },
  created () {
    const that = this
    storage.getItem('userId', event => {
      if (event.result === 'success') {
        that.userId = event.data
      }
    })
    that.carList = that.$route.query.paramsList
    for (let i = 0; i < that.carList.length; i++) {
      for (let j = 0; j < that.carList[i].goods.length; j++) {
        let price = that.carList[i].goods[j].discountPrice ? that.carList[i].goods[j].discountPrice : that.carList[i].goods[j].price
        that.allMoney += Number(price) * Number(that.carList[i].goods[j].amount)
      }
    }
  },
  mounted () {
    const that = this
    that.$api.get(faHuoMethod, {}, function (res) {
      that.fahuoTypeList = res.data
      that.chooseFaHuoType = that.fahuoTypeList[that.idx1].description
    })
    that.invoice = that.$route.query.params
    // 获取默认地址
    that.$api.get(morenAddress, {}, function (add) {
      that.addressList = add.data
    }, function () {}, true)
    // 获取地址列表
    that.$api.get(getAddress, {}, function (res) {
      that.shouHuoAddressList = res.data
    }, function () {}, true)
    // 获取发票信息
    that.$api.get(queryInvoice, {}, (res) => {
      if (res.data && res.data.id > 0) {
        that.invoiceId = res.data.id
      }
    }, () => {
    }, true)
  },
  methods: {
    chooseThisEnterprise (item, index) { // 选中类型后
      const that = this
      if (index === 0) {
        if (!that.invoiceId) {
          modal.toast({
            message: '请先填写发票信息'
          })
          that.$router.push('/invoice/invoice')
        }
      }
      that.chooseEnterpriseType = item.name
      that.idx = index
      that.typeSelectShow = false
    },
    chooseThisFaHuo (item, index) {
      this.typeFahuoShow = false
      this.idx1 = index
      this.chooseFaHuoType = item.description
    },
    // 选择发票类型
    chooseFaPiaoType () {
      this.typeSelectShow = true
    },
    closeTypeDialog () { // 关闭类型选择弹窗
      this.typeFahuoShow = false
    },
    closeFaPiaoDialog () {
      this.typeSelectShow = false
    },
    typeTouchStart (item, index) { // 点击效果
      this.idx = index
    },
    typeTouchEnd () {
      this.idx = -1
    },
    showFahuoType () {
      this.typeFahuoShow = true
    },
    // 跳转到收银台
    pushToCheckstand () {
      const that = this
      if (validatenull(that.userId)) {
        modal.toast({
          message: '用户未登录'
        })
        that.$router.push('/login')
      }
      if (!that.disAgree) {
        if (validatenull(that.addressList)) {
          modal.toast({
            message: '请选择收货地址'
          })
          return
        }
        let params = []
        for (let i = 0; i < that.carList.length; i++) {
          let obj = {
            shopsId: that.carList[i].shopId,
            shopsName: that.carList[i].shopName,
            orderRemark: that.oneText,
            userId: that.userId,
            payType: 1,
            agreement: 1,
            addressId: that.addressList.id,
            deliveryType: that.fahuoTypeList[that.idx1].value,
            invoiceId: that.invoiceId,
            goodsList: []
          }
          let total = 0
          for (let j = 0; j < that.carList[i].goods.length; j++) {
            let price = that.carList[i].goods[j].discountPrice ? that.carList[i].goods[j].discountPrice : that.carList[i].goods[j].price
            total += Number(price) * that.carList[i].goods[j].amount
            let objs = {
              shopsId: that.carList[i].shopId,
              goodsUrl: that.carList[i].goods[j].goodsUrl,
              goodsName: that.carList[i].goods[j].goodsName,
              goodsId: that.carList[i].goods[j].id,
              buyType: that.carList[i].goods[j].buyType,
              goodsType: that.carList[i].goods[j].goodsType,
              amount: that.carList[i].goods[j].amount,
              discountPrice: that.carList[i].goods[j].discountPrice,
              price: that.carList[i].goods[j].price
            }
            obj.goodsList.push(objs)
          }
          obj.actualPrice = total
          params.push(obj)
        }
        that.$api.post(productOrder, params, function (res) {
          that.$router.push('/myorder/storeOrder')
          // let orderId = ''
          // let orderNo = ''
          // for (let i in res.data) {
          //   orderId = i
          //   // orderNo = res.data[i]
          // }
          // that.$router.push({path: '/mine/waitGain', query: {orderId: orderId}})
          // that.$router.push({path: '/myorder/checkstand', query: {totalPrice: that.allMoney, orderId: orderId, orderNo: orderNo}})
        }, () => {}, true)
      } else {
        modal.toast({
          message: '请先同意《泳衣库协议》'
        })
      }
    },
    // 这些是我的收货地址列表
    pushToMyAddress () {
      const that = this
      that.shouHuoAddress = true
    },
    // 编辑收货地址
    pushToWriteAdd (item, addressId) {
      const that = this
      that.editAddress = true
      that.addressData = {
        id: addressId,
        consignee: item.consignee,
        phone: item.phone,
        address: item.address,
        openDefaultAddress: item.openDefaultAddress,
        provinceId: item.provinceId,
        cityId: item.cityId,
        districtId: item.districtId,
        provinceName: item.provinceName,
        cityName: item.cityName,
        districtName: item.districtName,
        write: true,
        baocun1: true
      }
    },
    // 关闭编辑收货地址
    closeeditAddress () {
      const that = this
      that.editAddress = false
      that.addressData = {
        id: '',
        consignee: '',
        phone: '',
        address: '',
        openDefaultAddress: '0',
        provinceId: '',
        cityId: '',
        districtId: '',
        provinceName: '',
        cityName: '',
        districtName: '',
        write: true,
        baocun1: false
      }
    },
    // 添加一个地址
    add () {
      const that = this
      that.addressData.consignee = ''
      that.addressData.phone = ''
      that.addressData.address = ''
      that.addressList = ''
      that.str = ''
      that.editAddress = true
      that.showNo = true
      that.showYes = false
    },
    // 关闭收货地址
    closeshouHuoAddress () {
      this.shouHuoAddress = false
    },
    backPage () {
      const that = this
      that.shouHuoAddress = false
      // 获取默认地址
      that.$api.get(morenAddress, {}, function (add) {
        that.addressList = add.data
      }, function () {}, true)
    },
    handleSelectArea () { // 选择地区
      this.addressShow = true
    },
    handleAddressCancel () { // 取消
      this.addressShow = false
      this.showNo = true
      this.showYes = false
    },
    handleAddressConfirm (obj) { // 确定
      // this.materialForm.address = str
      const that = this
      that.addressShow = false
      this.showNo = false
      this.showYes = true
      that.str = obj.str
      that.stringList = that.str.trim().split(/\s+/)
      that.idList = obj.val.trim().split(/\s+/)
    },
    chooseMoren () {
      const that = this
      that.addressData.openDefaultAddress = (that.addressData.openDefaultAddress === '1') ? '0' : '1'
      that.checkedIcon = (that.addressData.openDefaultAddress === '1')
    },
    // 是否同意协议
    changeXuanZhong () {
      const that = this
      if (that.disAgree) {
        that.disAgree = false
      } else {
        that.disAgree = true
      }
    },
    saveAddress () {
      const that = this
      if (that.checkedIcon) {
        that.addressData.openDefaultAddress = '1'
      } else {
        that.addressData.openDefaultAddress = '0'
      }
      const canshu = {
        id: that.addressData.id,
        consignee: that.addressData.consignee,
        phone: that.addressData.phone,
        address: that.addressData.address,
        provinceId: that.idList[0],
        cityId: that.idList[1],
        districtId: that.idList[2],
        provinceName: that.stringList[0],
        cityName: that.stringList[1],
        districtName: that.stringList[2],
        openDefaultAddress: that.addressData.openDefaultAddress
      }
      that.$api.post(updateAddress, canshu, function (res) {
        that.editAddress = false
        // 获取地址列表
        that.shouHuoAddress = true
        that.$api.get(getAddress, {}, function (res) {
          that.shouHuoAddressList = res.data
        }, function () {}, true)
      }, function () {}, true)
    },
    deleteAddress () {
      const that = this
      that.$api.post(deleteAddress + '/' + that.addressData.id, {}, function (res) {
        modal.toast({
          message: '删除成功'
        })
        that.editAddress = false
        that.shouHuoAddress = true
        that.$api.get(getAddress, {}, function (res) {
          that.shouHuoAddressList = res.data
        }, function () {}, true)
      })
    },
    // 新添加地址保存
    addNewAddress () {
      const that = this
      if (that.checkedIcon) {
        that.addressData.openDefaultAddress = '1'
      } else {
        that.addressData.openDefaultAddress = '0'
      }
      const canshu = {
        id: that.addressData.id,
        consignee: that.addressData.consignee,
        phone: that.addressData.phone,
        address: that.addressData.address,
        provinceId: that.idList[0],
        cityId: that.idList[1],
        districtId: that.idList[2],
        provinceName: that.stringList[0],
        cityName: that.stringList[1],
        districtName: that.stringList[2],
        openDefaultAddress: that.addressData.openDefaultAddress
      }
      that.$api.post(addAddress, canshu, function (res) {
        that.editAddress = false
        that.shouHuoAddress = true
        that.$api.get(getAddress, {}, function (res) {
          that.shouHuoAddressList = res.data
        }, function () {}, true)
      }, function () {}, true)
    },
    // 跳到生成订单
    pushToWriteOrder (id) {
      const that = this
      that.shouHuoAddress = false
      that.$api.get(searchAddress + '/' + id, {}, function (res) {
        that.addressList = res.data
      })
    },
    handleXianHuo (item) {
    },
    // 查看更多
    lookMore (item) {
      const that = this
      that.moreGoodList = item.goods
      that.moreGoodShow = true
    },
    closemoreGoodShow () {
      const that = this
      that.moreGoodShow = false
    },
    stopEvent (e) {
      const { platform } = weex.config.env
      platform === 'Web' && e.preventDefault && e.preventDefault()
    }
  },
  components: {
    IHeader,
    WxcPopup,
    Address,
    Radio,
    Check
  }
}
</script>

<style scoped>
    .contact {
        flex-direction: column;
        padding-top: 24px;
        padding-bottom: 24px;
        padding-left: 24px;
        padding-right: 24px;
        /*margin-top: 16px;*/
    }

    .contact-info {
        flex-direction: row;
        align-items: flex-end;
    }
    .name {
        font-size: 30px;
        color: rgb(70, 70, 70);
    }

    .tel {
        font-size: 30px;
        color: rgb(70, 70, 70);
        margin-left: 24px;
    }

    .addr {
        margin-top: 20px;
        flex-direction: row;
        justify-content: space-between;
    }

    .address {
        font-size: 26px;
        color: red;
        width: 615px;
        flex-wrap: wrap;
    }

    .arrow {
        width: 15px;
        height: 25px;
    }

    .xianImg {
        width: 750px;
        height: 8px;
    }

    .xian {
        width: 750px;
        height: 16px;
        background-color: rgb(245, 245, 245);
    }

    .row {
        height: 88px;
        padding-left: 26px;
        padding-right: 26px;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }

    .paytext {
        font-size: 28px;
        color: rgb(134, 134, 134);
        line-height: 88px;
    }

    .pay {
        flex-direction: row;
        align-items: center;
    }

    .text1 {
        font-size: 28px;
        color: rgb(70, 70, 70);
        font-wight: bold;
        margin-right: 20px;
    }

    .store {
        flex-direction: column;
    }

    .store-item {
        padding-top: 18px;
        padding-left: 24px;
        padding-right: 24px;
        flex-direction: column;
    }

    .store-info {
        flex-direction: row;
        align-items: center;
    }

    .storename {
        font-size: 30px;
        color: rgb(134, 134, 134);
    }

    .storeImg {
        width: 34px;
        height: 34px;
        margin-right: 17px;
    }

    .good-wrap {
        flex-direction: column;
    }

    .good-item {
        margin-top: 20px;
        background-color: rgb(235, 235, 235);
        padding-top: 16px;
        padding-bottom: 16px;
        padding-left: 16px;
        padding-right: 16px;
        border-top-left-radius: 10px;
        border-top-right-radius: 10px;
        border-bottom-left-radius: 10px;
        border-bottom-right-radius: 10px;
        align-items: center;
        flex-direction: row;
        justify-content: space-between;
    }
    .goodImg {
        width: 128px;
        height: 128px;
        border-top-left-radius: 8px;
        border-top-right-radius: 8px;
        border-bottom-left-radius: 8px;
        border-bottom-right-radius: 8px;
        margin-right: 15px;
    }

    .detail-info{
        width: 500px;
        flex-direction: row;
        margin-top:14px;
        justify-content: space-between;
    }
    .hebing{
        flex-direction: row;
        align-items: flex-end;
    }
    .good-left{
        flex-direction: row;
    }
    .goodname {
        font-size: 28px;
        font-weight: bold;
        color: rgb(70, 70, 70);
        lines: 1;
        overflow: hidden;
        flex: 1;
        text-overflow: ellipsis;
    }

    .good-right {
        margin-left: 15px;
        width: 500px;
    }

    .type {
        flex-direction: row;
        margin-right: 27px;
        align-items: center;
    }

    .text {
        font-size: 24px;
        color: rgb(134, 134, 134);
    }

    .num {
        position: absolute;
        right: 0;
    }

    .price {
        flex-direction: row;
        margin-top: 26px;
    }

    .nowPrice {
        flex-direction: row;
        margin-right: 24px;
        align-items: center;
    }

    .money {
        font-size: 24px;
        font-weight: bold;
        color: rgb(70, 70, 70);

    }

    .oldmoney {
        font-size: 24px;
        color: rgb(134, 134, 134);
        text-decoration: line-through;
    }

    .row1 {
        border-bottom-color: rgb(235, 235, 235);
        border-bottom-style: solid;
        border-bottom-width: 1px;
    }

    .beizhu {
        flex-direction: column;
        padding-top: 30px;
        padding-bottom: 30px;
        padding-left: 24px;
        padding-right: 24px;
    }

    .beizhutext {
        font-size: 28px;
        color: rgb(134, 134, 134);
        margin-bottom: 15px;
    }

    .beizhuCon {
        width: 702px;
        height: 145px;
        background-color: rgb(245, 245, 245);
        text-align: left;
        padding-left: 15px;
        padding-top: 17px;
        padding-right: 17px;
        font-size: 28px;
    }
    .priceRow{
        height: 88px;
        flex-direction: row;
        padding-left:25px;
        align-items:center;
        box-shadow: 1px 0px 0px 0px rgba(43,48,64,0.12);
    }
    .jine{
        font-size:28px;
        font-weight:bold;
        color:rgb(70,70,70)
    }
    .mon{
        flex-direction: row;
        align-items: flex-end;
        margin-left:25px;
    }
    .moneytext{
        color:rgb(254,203,1);
        font-size:28px;
        font-weight:bold;
    }
    .icon{
        width:24px;
        height:24px;
        border-top-left-radius: 12px;
        border-top-right-radius: 12px;
        border-bottom-left-radius: 12px;
        border-bottom-right-radius: 12px;
        margin-right:25px;
    }
    .agree{
        font-size:24px;
        color:rgb(134,134,134)
    }
    .footer{
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        flex-direction: row;
        align-items: center;
        height: 98px;
        justify-content: space-between;
        box-shadow: 1px 0px 4px 1px rgba(43,48,64,0.12);
    }
    .left{
        width:460px;
        flex-direction: row;
        align-items: center;
        justify-content: center;
        height: 98px;
    }
    .right{
        width: 270px;
        background-color:rgb(43,48,64);
        font-size:30px;
        height:98px;
        align-items: center;

    }
    .yingfu{
        font-size: 28px;
        color:rgb(70,70,70);
    }
    .apply{
        font-size: 30px;
        line-height:98px;
        text-align:center;
        color: #fff;
    }
    .more{
        width: 52px;
        height: 16px;
        flex: 1;
    }
    .row2{
        flex-direction: row;
        justify-content: space-between;
        height:88px;
        width:698px;
        border-bottom-color: rgb(245,245,245);
        border-bottom-style: solid;
        border-bottom-width: 1px;
        align-items: center;
    }
    .beforepress{
        background-color: #fff;
    }
    .afterpress {
        background-color: rgba(43,48,64,0.2);
    }
    .enterprise-item {
        padding-left: 24px;
        padding-right: 24px;
    }
    .enterprise-name {
        font-size: 26px;
    }
    .write {
        padding-right: 44px;
        text-align: right;
        border-width: 0px;
        font-size: 26px;
        placeholder-color: #cecece;
    }
    .enterpriseName {
        width: 512px;
    }
    .enterpriseNumber {
        width: 305px;
    }
    .enterprise-list{
        margin-top: 88px;
        min-height: 700px
    }
    .enterprise-item {
        padding-left: 24px;
        padding-right: 24px;
    }
    .enterprise-name {
        font-size: 26px;
    }
    .item-height {
        height: 88px;
        line-height: 88px;
    }
    .wrap {
        position: fixed;
        top: 88px;
        bottom: 0;
        left: 0;
        right: 0;
        background-color: rgb(235, 235, 235);
    }
    /*.contact {*/
        /*flex-direction: column;*/
        /*padding-top: 24px;*/
        /*padding-bottom: 24px;*/
        /*padding-left: 24px;*/
        /*padding-right: 24px;*/
        /*margin-top: 16px;*/
        /*background-color: #fff;*/
    /*}*/
    .name {
        font-size: 30px;
        color: rgb(70, 70, 70);
        font-weight: bold;
    }

    .tel {
        font-size: 30px;
        color: rgb(70, 70, 70);
        margin-left: 24px;
        font-weight: bold;
    }

    .addr {
        padding-top: 18px;
        flex-direction: row;
        justify-content: space-between;
    }

    .address {
        font-size: 26px;
        color: rgb(134, 134, 134);
        width: 615px;
        flex-wrap: wrap;
    }

    .moren {
        font-size: 22px;
        color: rgb(255, 15, 55);
        margin-left: 25px;
    }

    .addImg {
        width: 40px;
        height: 40px;
        margin-top: -11px
    }

    .xianImg {
        width: 750px;
        height: 8px;
    }

    .xian {
        width: 750px;
        height: 16px;
        background-color: rgb(245, 245, 245);
    }
    .col_fff {
        color: #fff;
    }
    .regular {
        font-family: regular;
    }
    .medium {
        font-family: medium;
    }
    .header {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        flex-wrap: wrap;
        flex-direction: row;
        height: 88px;
        background-image: linear-gradient(to right, #2b3040, #7d88a4);
    }
    .backPage {
        width: 200px;
        flex-direction: row;
        align-items: center;
        padding-right: 8px;
        padding-left: 24px;
    }
    .arrow_left {
        width: 24px;
        height: 40px;
        margin-right: 16px;
    }
    .back {
        font-size: 32px;
        line-height: 88px;
    }
    .title {
        width: 350px;
        text-align: center;
        font-size: 36px;
        font-weight: bold;
        line-height: 88px;
    }

    .btn-wrapper {
        width: 200px;
        padding-right: 24px;
        flex-direction: row;
        align-items: center;
        justify-content: flex-end;
    }
    .btn{
        text-align: right;
        line-height: 88px;
        font-size: 32px;
        color: #cecece;
        font-family: medium;
    }
    .my-address{
        background-color: rgb(245,245,245);
    }
    .inputRows{
        height: 88px;
        padding-left: 24px;
        padding-right: 24px;
        background-color: #fff;
    }
    .input{
        flex-direction: row;
        height: 87px;
        border-bottom-style: solid;
        border-bottom-color: rgb(245,245,245);
        border-bottom-width: 1px;
        width: 700px;
        justify-content: space-between;
        align-items: center;
        color:rgb(70,70,70)
    }
    .rowtext{
        font-weight:bold;
        color:rgb(134,134,134);
        font-size:28px;
        width: 130px;
        height: 88px;
        line-height: 90px;
    }
    .rowImg{
        width:40px;
        height:40px;
    }
    .left{
        flex-direction: row;
        align-items: center;
    }
    .rowInput{
        font-size:28px;
        margin-left:20px;
        width:420px;
        color: rgb(70,70,70);
        font-weight:bold;
        height: 50px;
    }
    .addInput {
        width: 450px;
    }
    .arrowImg{
        width: 24px;
        height:36px;
    }
    .choose{
        font-size:28px;
        color:rgb(206,206,206);
        margin-right: 20px;
    }
    .addInput{
        width: 570px;
        font-size:28px;
        font-weight:bold;
        color:rgb(70,70,70)
    }
    .setting{
        padding-left: 24px;
        flex-direction: row;
        margin-top:40px;
        align-items:center
    }
    .morenImg{
        width: 40px;
        height: 40px;
        margin-right:20px;
    }
    .morentext{
        font-size:28px;
        color:rgb(70,70,70);
        font-weight:bold;
        margin-left: 15px;
    }
    .addstr{
        color:rgb(70,70,70);
        font-weight:bold;
        font-size:28px;
    }
    .delete{
        margin-top: 100px;
        justify-content: center;
        flex-direction:row;
    }
    .delete-btn{
        width:565px;
        height:70px;
        border-width:1px;
        border-style:solid;
        border-color:rgb(43,48,64);
        border-radius: 10px;
        line-height:70px;
        text-align:center;
        color:rgb(43,48,64);
        font-size: 26px;
        font-family:medium;
        background-color: #fff;
    }
    .col_fff {
        color: #fff;
    }
    .regular {
        font-family: regular;
    }
    .medium {
        font-family: medium;
    }
    .header {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        flex-wrap: wrap;
        flex-direction: row;
        height: 88px;
        background-image: linear-gradient(to right, #2b3040, #7d88a4);
    }
    .backPage {
        width: 200px;
        flex-direction: row;
        align-items: center;
        padding-right: 8px;
        padding-left: 24px;
    }
    .arrow_left {
        width: 24px;
        height: 40px;
        margin-right: 16px;
    }
    .back {
        font-size: 32px;
        line-height: 88px;
    }
    .title {
        width: 350px;
        text-align: center;
        font-size: 36px;
        font-weight: bold;
        line-height: 88px;
    }
    .btn-wrapper {
        width: 200px;
        padding-right: 24px;
        flex-direction: row;
        align-items: center;
        justify-content: flex-end;
    }
    .leftInput {
        flex-direction: row;
        align-items: center;
    }
    .wrap1{
        background-color: rgb(245,245,245);
        position: fixed;
        top:0;
        margin-top: 88px;
        padding-top: 150px;
        bottom: 0;
        left: 0;
        right: 0;
        flex-direction:column;
        align-items: center;
    }
    .nullAddress{
        width:470px;
        height:295px;
    }
    .nulltext{
        font-size: 30px;
        color:rgb(206,206,206);
        font-weight:bold;
        margin-top: 25px;
    }
    .conwrap{
        padding-bottom: 98px;
        background-color: #fff;
    }
    .radioItem {
        margin-left: 60px;
    }
    .good-rightimg{
    }
    .moreHeader{
        height: 88px;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        width: 700px;
    }
    .headerText{
        flex-direction: row;
    }
    .titletext1{
        color: rgb(134,134,134);
        font-size: 28px;
    }
    .titletext2{
        color:rgb(70,70,70);
        font-wight:bold;
        font-size: 28px;
        margin-left: 23px;
    }
    .closeImg{
        width:30px;
        height:30px;
    }
    .dialog-content1{
        border-top-left-radius: 20px;
        border-top-right-radius: 20px;
        padding-bottom: 30px;
        position: absolute;
        bottom: 0;
        background-color: #fff;
    }
    .moremodal{
        position: fixed;
        top:0;
        bottom:0;
        left: 0;
        right: 0;
        background-color: rgba(0,0,0,0.6)
    }
    /*.detail-info{*/
        /*width:520px;*/
    /*}*/
    .contact-item {
        background-color: #fff;
        margin-top: 16px;
    }
</style>
